﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.TemplateLanguage;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Web;

namespace MethodWorx.CMS.Plugins
{
    public class PageTmlExtension : IParser
    {

        public Func<CmsRequestContext, Page, Dictionary<string, object>, object> Parser { get; set; }

        #region IParser Members

        public string[] Parameters { get { return new string[] { }; } }

        public object Parse(CmsRequestContext context, IEnumerable<object> stack, Dictionary<string, object> parameters)
        {
            var page = stack.OfType<MethodWorx.CMS.Content.Page>().FirstOrDefault();
            if (page == null)
                throw new Exception("Page does not exist on stack");

            return this.Parser(context, page, parameters);
        }

        public string Name
        {
            get;
            set;
        }

        public string Namespace
        {
            get;
            set;
        }

        #endregion
    }
}
